<!-- 主页部分 -->
<template>
  <div class="container">
    <div class="navTab">
      <img src="@/assets/img/icon-search.png" alt="" class="search" />
      <input type="text" placeholder="搜索关键词" class="input" />
    </div>
    <div class="banner">
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="#39a9ed">
        <van-swipe-item v-for="item in slider" :key="item.src">
          <a :href="item.href"><img v-lazy="item.src" /></a>
        </van-swipe-item>
      </van-swipe>
    </div>
    <div class="nav">
      <div
        class="nav-items"
        @click.stop="goToDetail(item)"
        v-for="item in gridNav.items"
        :key="item.href"
      >
        <img :src="item.src" alt="" />
        <span>{{ item.name }}</span>
      </div>
    </div>
    <div class="blank">
      <Blank :height="blank.height" :bgcolor="blank.bgcolor"></Blank>
    </div>
    <div class="gzh">
      <div class="mask" v-show="isShow" @click="hide">
        <div class="modal" @click.stop="show">
          <img src="http://h5.xiaomage.tech/static/img/topright.548189da.png" class="top-right" />
          <div class="title">关注公众号</div>
          <div class="body">
            <div class="qrcode">
              <img :src="gzh.qrcode" />
            </div>
          </div>
          <div class="tip">长按二维码识别或截图保存</div>
        </div>
      </div>
      <div class="gzh-left">
        <div class="gzh-left-logo">
          <img :src="gzh.logo" alt="" />
        </div>
        <div class="gzh-left-info">
          <div class="gzh-left-info-name">{{ gzh.name }}</div>
          <div class="gzh-left-info-desc">{{ gzh.desc }}</div>
        </div>
      </div>
      <div class="gzh-right">
        <div class="gzh-right-btn" @click="show">关注</div>
      </div>
    </div>
    <div class="main-class">
      <div class="main-class-title">
        <div class="main-class-title-text">{{ vod.title }}</div>
        <div class="more" @click="toShowMore"><span>查看更多</span></div>
      </div>
      <div class="main-class-body">
        <ClassItem v-for="item in vod.items" :key="item.id" :item="item"></ClassItem>
      </div>
    </div>
    <TechSupport></TechSupport>
    <FooterNav type="home"></FooterNav>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import Vue from "vue";
import { Swipe, SwipeItem, Lazyload } from "vant";
import Blank from "@/components/Blank.vue";
import ClassItem from "@/components/ClassItem.vue";
import TechSupport from "@/components/TechSupport.vue";
import FooterNav from "@/components/FooterNav.vue";
Vue.use(Swipe);
Vue.use(SwipeItem);
Vue.use(Lazyload);
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {
    Blank,
    ClassItem,
    TechSupport,
    FooterNav,
  },
  data() {
    //这里存放数据
    /* 2. 定义两个数据
       2.1 blocks  存储整个页面的数据
       2.2 slides  存储页面的轮播图数据
   */
    return {
      block: [],
      slider: [],
      gridNav: [],
      blank: {},
      gzh: {},
      vod: {},
      isShow: false,
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    goToDetail(item) {
      this.$router
        .push({
          path: "/vod/detail",
          query: {
            id: item.href.split("?")[1].split("=")[1],
          },
        })
        .catch(err);
    },
    // goToClassDetail(item) {
    //   this.$router.push({
    //     path: "/vod/detail",
    //     id: item.id,
    //   });
    // },
    show() {
      this.isShow = true;
    },
    hide() {
      this.isShow = false;
    },
    toShowMore() {
      this.$router.push({
        name: "vod",
      });
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  async created() {
    // 1. 通过请求获取首页数据
    let res = await this.$request.get("/api/v2/viewBlock/page/blocks", {
      // 固定有一个key params
      params: {
        platform: "h5",
        page_name: "h5-page-index",
      },
    });
    // .then(
    //   function (res) {
    //     console.log(res);
    //   },
    //   function (error) {
    //     console.log(error);
    //   }
    // );
    this.block = res.data;
    res.data.forEach((element) => {
      if (element.sign == "slider") {
        this.slider = element.config_render;
      } else if (element.sign == "grid-nav") {
        this.gridNav = element.config_render;
      } else if (element.sign == "blank") {
        this.blank = element.config_render;
      } else if (element.sign == "h5-gzh-v1") {
        this.gzh = element.config_render;
      } else if (element.sign == "h5-vod-v1") {
        this.vod = element.config_render;
      }
    });
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang="less" scoped>
@keyframes window-open {
  0% {
    transform: translateY(120px);
  }
  100% {
    transform: translateY(0px);
  }
}
.container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #f6f6f6;
  overflow-x: hidden;
  overflow-y: scroll;
  .navTab {
    width: 100%;
    height: 1.333333rem;
    background: #fff;
    position: relative;
    display: flex;
    padding: 0.213333rem 0.4rem;
    .search {
      width: 0.426667rem;
      height: 0.426667rem;
      position: absolute;
      top: 0.453333rem;
      left: 0.986667rem;
      cursor: pointer;
    }

    .input {
      width: 100%;
      height: 0.906667rem;
      background: #f5f5f5;
      border-radius: 0.453333rem;
      outline: none;
      border: none;
      padding-left: 1.333333rem;
      font-size: 0.373333rem;
    }
  }
  .banner {
    width: 100%;
    padding: 8px 15px;
    // height: 3.066667rem;
    margin: 0 auto;
    background-color: #fff;
    overflow: hidden;
    .my-swipe .van-swipe-item {
      border-radius: 8px;
      overflow: hidden;
      color: #fff;
      font-size: 20px;
      text-align: center;
      width: 100%;
      // background-color: #39a9ed;
      img {
        width: 100%;
        height: 3.066667rem;
      }
    }
  }
  .nav {
    display: flex;
    padding: 10px;
    background-color: white;
    .nav-items {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      img {
        width: 1.333333rem;
        height: 1.333333rem;
        margin-bottom: 5px;
      }

      span {
      }
    }
  }
  .gzh {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background-color: #fff;
    .mask {
      position: fixed;
      z-index: 999;
      // width: 100%;
      // height: 100%;
      top: 0;
      right: 0;
      left: 0;
      bottom: 0;
      background: rgba(0, 0, 0, 0.6);
      .modal {
        position: fixed;
        z-index: 999;
        width: 5.333333rem;
        height: 6.293333rem;
        top: calc(50% - 118px);
        left: calc(50% - 100px);
        background-color: #fff;
        border-radius: 8px;
        overflow: hidden;
        -webkit-animation: window-open 0.3s;
        animation: window-open 0.3s;
        display: flex;
        flex-direction: column;
        .top-right {
          position: absolute;
          top: 3px;
          right: 0;
          width: 64px;
          height: 67px;
        }

        .title {
          width: 100%;
          margin-top: 20px;
          height: 14px;
          font-size: 14px;
          font-weight: 500;
          color: #333;
          line-height: 14px;
          text-align: center;
        }

        .body {
          width: 100%;
          margin-top: 20px;
          height: 120px;
          display: flex;
          justify-content: center;
          .qrcode {
            width: 120px;
            height: 120px;
            img {
              width: 120px;
              height: 120px;
            }
          }
        }

        .tip {
          width: 100%;
          margin-top: 20px;
          height: 12px;
          font-size: 12px;
          font-weight: 400;
          color: #999;
          line-height: 12px;
          text-align: center;
        }
      }
    }
    .gzh-left {
      display: flex;
      align-items: center;
      .gzh-left-logo {
        margin-right: 10px;
        img {
          width: 1.333333rem;
          height: 1.333333rem;
          border-radius: 50%;
        }
      }

      .gzh-left-info {
        .gzh-left-info-name {
          width: 100%;
          height: 20px;
          font-size: 15px;
          font-weight: 500;
          color: #171923;
          line-height: 20px;
          margin-top: 5px;
          overflow: hidden;
        }

        .gzh-left-info-desc {
          width: 100%;
          height: 12px;
          font-size: 12px;
          font-weight: 400;
          color: #999;
          line-height: 12px;
          margin-top: 8px;
          overflow: hidden;
        }
      }
    }

    .gzh-right {
      .gzh-right-btn {
        width: 1.546667rem;
        height: 0.64rem;
        line-height: 0.64rem;
        background-color: #3ca7fa;
        border-radius: 12px;
        font-size: 14px;
        font-weight: 400;
        color: #fff;
        justify-content: center;
        text-align: center;
      }
    }
  }
  .main-class {
    width: 100%;
    margin-top: 10px;
    background: #fff;
    padding: 25px 15px 20px 15px;
    display: flex;
    flex-direction: column;
    .main-class-title {
      width: 100%;
      height: 19px;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 25px;
      .main-class-title-text {
        height: 19px;
        font-size: 19px;
        font-weight: 600;
        color: #333;
        line-height: 19px;
      }

      .more {
        display: inline-block;
        width: auto;
        height: 13px;
        font-size: 13px;
        font-weight: 400;
        color: #999;
        line-height: 13px;
        cursor: pointer;
        span {
          font-size: 13px;
          font-weight: 400;
          color: #999;
          line-height: 13px;
          cursor: pointer;
        }
      }
    }
    .main-class-body {
      width: 100%;
    }
  }
  .foot-nav {
    width: 100%;
    padding: 5px 50px;
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    justify-content: space-between;
    background-color: #fff;
    .foot-nav-item {
      background-color: #fff;
      img {
        width: 0.746667rem;
        height: 0.746667rem;
        margin-bottom: 3px;
      }
      span {
        display: block;
        text-align: center;
      }
    }
  }
}
</style>
